package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SupplierBean;
import com.project.mapper.ISupplierMapper;
import com.project.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private ISupplierMapper supplierMapper;

    /**
     * 动态条件分页查询
     *
     * @param pageNo   页码
     * @param name     供货商名字
     * @param business 经营范围
     * @return 返回分页集合
     */
    @Override
    public IPage<SupplierBean> findByItem(Integer pageNo, String name, String business) {
        return (Page<SupplierBean>) supplierMapper.findByItem(new Page(pageNo, 3), name, business);
    }

    /**
     * 按id查询供应商
     *
     * @param id 供应商id
     * @return 供应商对象
     */
    @Override
    public SupplierBean findById(Integer id) {
        return supplierMapper.selectById(id);
    }

    /**
     * 按id修改负责人，负责人电话
     *
     * @param id    供货商id
     * @param user  负责人
     * @param phone 负责人电话
     */
    @Override
    public void update(Integer id, String user, String phone) {
        SupplierBean supplier = supplierMapper.selectById(id);
        supplier.setUser(user);
        supplier.setPhone(phone);
        supplierMapper.updateById(supplier);
    }

    /**
     * 添加供应商对象
     *
     * @param supplier 供应商对象
     */
    @Override
    public void add(SupplierBean supplier) {
        System.out.println("22222" + supplier);
        supplierMapper.insert(supplier);
    }

    /**
     * 查询所有供货商
     *
     * @return 供货商集合
     */
    @Override
    public List<SupplierBean> findAll() {
        return supplierMapper.selectList(null);
    }

    /**
     * 批量添加供应商
     *
     * @param supplierList 供应商集合
     */
    @Override
    public void addList(List<SupplierBean> supplierList) {
        supplierMapper.addList(supplierList);
    }
}
